// @ts-nocheck
// type Replace<T extends string, S extends string, C extends string, F = ""> = T extends "" ? 
// (S extends "" ? (C extends "" ?  "" : C): "")
// // 构建一个查找规则，找到后将左边和右边留起来${infer L}${C}${infer R} ${F}${L}${RC}
// : S extends "" ? T : T extends `${infer L}${S}${infer R}` ? `${F}${L}${C}${Replace<R,S,C>}` : ""; 

type Replace<
T extends string , 
C extends string, 
RC extends string, 
F extends string = ''
> = C extends "" 
    ? T extends "" 
    ? RC 
    : `${RC}${T}`
    : T extends `${infer L}${C}${infer R}` 
    ? Replace<R, C, RC, `${F}${L}${RC}`> 
    : `${F}${T}`;
type a1 = Replace<"ha ha ha", "ha", "he">;
type a2 = Replace<"jw","jw","jiangwen">;
type a3 = Replace<"a","","jiangwen">;
type a4 = Replace<"","","jiangwen">;
export {}


